#include "tcStateHelp.h"
#include <GL/freeglut.h>
#include <juanmabc.h>
#include "tcGame.h"
#include "tcStateMain.h"

void
tcStateHelpIn(void)
{
	TCGame *game;

	game = tcGame();
}

void
tcStateHelpOut(void)
{
	TCGame *game;

	game = tcGame();

}

void
tcStateHelpKeyboard(unsigned char key, int x, int y)
{
	TCGame *game;

	game = tcGame();
}

void
tcStateHelpKeyboardUp(unsigned char key, int x, int y)
{
	TCGame *game;

	game = tcGame();

	if(key == 27)
	{
		alSourcePlay(game->general.sounds[2]);
		tcStateHelpOut();
		game->state = TC_STATE_MAIN;
		tcStateMainIn();
	}
}

void
tcStateHelpSpecial(int key, int x, int y)
{
	TCGame *game;

	game = tcGame();
}

void
tcStateHelpSpecialUp(int key, int x, int y)
{
	TCGame *game;

	game = tcGame();
}

void
tcStateHelpFrame(void)
{
	TCGame *game;
	unsigned int i;
	unsigned int w, h;
	float tw, th;

	game = tcGame();

	gluLookAt(0.0f, 0.0f, 350.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); 

	tw = th = 0.0f;
	for(i = 0; i < game->help.nstrs; i++)
	{
		flFontStringMetrics(game->general.font, game->help.strs[i], &w, &h);
		tw = tw >= w ? tw : w;
		th += i < game->help.nstrs - 1 ? (float) h * 1.5f : (float) h;
	}

	glPushMatrix();
	glScalef(0.55f * game->general.display.aspect, 0.55f * game->general.display.aspect, 0.55f * game->general.display.aspect);
	glTranslatef(0.0f, th / 2.0f, 0.0f);
	for(i = 0; i < game->help.nstrs; i++)
	{
		flFontStringMetrics(game->general.font, game->help.strs[i], &w, &h);

		glDisable(GL_CULL_FACE);
		glEnable(GL_TEXTURE_GEN_S);
		glEnable(GL_TEXTURE_GEN_T);
		glMatrixMode(GL_TEXTURE);
		glPushMatrix();
		glScalef(0.1f, 0.1f, 0.1f);
		glMatrixMode(GL_MODELVIEW);

		mlMaterialBind(game->general.fontmat);

		glPushMatrix();
		glTranslatef(- (float) w / 2.0f, - (float) h, 0.0f);
		flFontDrawStringFill(game->general.font, game->help.strs[i]);
		glPopMatrix();

		glMatrixMode(GL_TEXTURE);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
		glDisable(GL_TEXTURE_GEN_S);
		glDisable(GL_TEXTURE_GEN_T);
		glEnable(GL_CULL_FACE);

		glTranslatef(0.0f, - (float) h * 1.5f, 0.0f);

	}
	glPopMatrix();

}
